The Decision making statements is a one type of control flow statements. it is also called branching statements or selection statements. the computer takes the decision which statements get executed . the computer decide the which statement is execute first. there are four types of if conditions.
The simple if statement is a condition based statements . and one way decision making statement. it have single if condition and one single statement based on condition the statement get executed. if condition is true then the statement one will executed otherwise next condition is .
If condition:
Statement
X=10
if x>5:
print("x is greater then 5")
It Is a another decision making statement. if condition is true then the statement block will be executed otherwise else statement block will be executed two way decision making statement.
if condition:
Statement true
Else:
Statement false
x=10
y=5
if x>y:
print(" X is greater then y")
else:
print("x is less then y")
This is the multi way decision making statement. which have multiple conditions in sequence . based on conditions the stements get executed. if condition 1 is true then the statement 1 get executed otherwise it moves into condition 2 . if condition 2 is true then the statement get executed otherwise the next condition means the evaluate condition n-1 is true then the true statement is executed otherwise the false statement get executed. the Examples in the below.
if condition1:
statement1
elif condition2:
statement2
elif condition n-1:
statement n-1
else:
statement n
marks=int(input("Enter your marks"))
if marks>86 and Marks<=90:
print("A Grade")
elif marks>65 and marks<=85:
print("B grade")
elif marks>45 and marks<=64:
print("c grade")
else:
print("Fail")
The nested if statement is a one type of decision making statement the program mean the python program can have if within another if condition is called nested is statement and if condition1 is true then the condition2 will get evaluated other wise the condition3 is evaluated. if condition2 is true then then the true statement get executed otherwise the else statement get executed. Example in the below
if Condition1:
if condition2:
statement true
else:
Statement false
else:
if condition3:
statement true
else:
statement false
number=int(input("Enter a number"))
if number%2=0:
if number%2==0:
print("The Given number is odd")
else:
print("The given number is not odd")
else:
if number%1=0:
print("The given number is Even")
else:
print("The given nuber is not even")